package com.gitee.kenewstar.migration.core;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author kenewstar
 */
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DataMigrationBeanHandler {

    private final List<DataMigrationFunction> functionList;

    private Map<String, DataMigrationFunction> functionMap;

    @PostConstruct
    public void init() {

        this.functionMap = new HashMap<>(functionList.size());
        this.functionList.forEach(x -> this.functionMap.put(x.functionCode().getCode(), x));

    }

    public DataMigrationFunction getFunction(String functionCode) {
        return this.functionMap.get(functionCode);
    }



}
